AccountCategory:

<?php
function showaccount($name,$code,$at,$accode)
{
  echo "
<br>&nbsp;&nbsp;$code:
<br>&nbsp;&nbsp;&nbsp;&nbsp;name: $name
<br>&nbsp;&nbsp;&nbsp;&nbsp;code: $code
<br>&nbsp;&nbsp;&nbsp;&nbsp;AccountType: $at
<br>&nbsp;&nbsp;&nbsp;&nbsp;parent_code: $accode
";
}


$asset="
0	ASSETS
1	CURRENT ASSETS
2	CASH
3	Cash on Hand
3	Cash in National Treasury
3	Cash in Bank - Local Currency
3	Cash in Bank - Foreign Currency
1	RECEIVABLES
2	Receivable Accounts
2	Inter-Agency Receivables
2	Intra-Agency Receivables
2	Other Receivables
1	INVENTORIES
2	Materials
2	Supplies
2	Agricultural, Fishery and Forestry Products
1	PREPAYMENTS
1	OTHER CURRENT ASSETS
1	INVESTMENTS
2	INVESTMENTS IN SECURITIES
2	SINKING FUND
1	PROPERTY, PLANT AND EQUIPMENT
2	LAND AND LAND IMPROVEMENTS
2	BUILDINGS
2	LEASEHOLD IMPROVEMENTS
2	OFFICE EQUIPMENT, FURNITURE AND FIXTURES
2	MACHINERIES AND EQUIPMENT
2	TRANSPORTATION EQUIPMENT
2	OTHER PROPERTY, PLANT AND EQUIPMENT
2	PUBLIC INFRASTRUCTURES
2	REFORESTATION PROJECTS
2	CONSTRUCTION IN PROGRESS
3	Agency Assets
3	Public Infrastructures/Reforestation Projects
1	OTHER ASSETS
";

$liability="
0	LIABILITIES
1	CURRENT LIABILITIES
2	Payable Accounts
2	Inter - Agency Payables
2	Intra - Agency Payables
2	Other Liability Accounts
1	LONG - TERM LIABILITIES
2	Mortgage/Bonds/Loans Payable
1	DEFERRED CREDITS
";
$equity="
0	EQUITY
1	GOVERNMENT EQUITY
1	INTERMEDIATE ACCOUNTS
";
$income="
0	INCOME
1	TAX REVENUE
2	National Taxes
2	Local Taxes
1	GENERAL INCOME ACCOUNTS
2	Permits and Licenses
2	Service Income
2	Business Income
2	Subsidy Income
2	Other Income
1	GAIN/LOSS ACCOUNTS
";
$expense="
0	EXPENSES
1	PERSONAL SERVICES
2	Salaries and Wages
2	Other Compensation
2	Personnel Benefits Contributions
2	Other Personnel Benefits
1	MAINTENANCE AND OTHER OPERATING EXPENSES
2	Traveling Expenses
2	Training and Scholarship Expenses
2	Supplies and Materials Expenses
2	Utility Expenses
2	Communication Expenses
2	Professional Services
2	Repairs and Maintenance
3	Land Improvements
3	Buildings
3	Leasehold Improvements
3	Office Equipment, Furniture and Fixtures
3	Machineries and Equipment
3	Transportation Equipment
3	Other Property, Plant and Equipment
3	Public Infrastructures
3	Reforestation Projects
2	Subsidies and Donations
2	Confidential, Intelligence, Extraordinary and Miscellaneous Expenses
2	Taxes, Insurance Premiums and Other Fees
2	Non-Cash Expenses
3	Bad Debts
3	Depreciation
4	Land Improvements
3	Buildings
3	Leasehold Improvements
4	Office Equipment, Furniture and Fixtures
3	Machineries and Equipment
3	Transportation Equipment
3	Other Property, Plant and Equipment
2	Depletion
3	Obsolescence - IT Software
2	Discounts
2	Tax Exemptions and Refunds
2	Remittance to National Treasury from Assets Disposal
2	Other Maintenance and Operating Expenses
1	FINANCIAL EXPENSES

";

$l0="";
$l1="";
$l2="";
$l3="";
$l4="";

class CodeMgr
{
  private $l0="";
  private $l1="";
  private $l2="";
  private $l3="";
  private $l4="";
  function getparentcode($level)
  {
    switch($level)
    {
      case 4:
        return $this->l3;
        break;
      case 3:
        return $this->l2;
        break;
      case 2:
        return $this->l1;
        break;
      case 1:
        return $this->l0;
        break;
      case 0:
        return "root";
        break;
    }
  }
  function setparentcode($level,$code)
  {
    switch($level)
    {
      case 4:
        $this->l4=$code;
        break;
      case 3:
        $this->l4="";
        $this->l3=$code;
        break;
      case 2:
        $this->l4="";
        $this->l3="";
        $this->l2=$code;
        break;
      case 1:
        $this->l4="";
        $this->l3="";
        $this->l2="";
        $this->l1=$code;
        break;
      case 0:
        $this->l4="";
        $this->l3="";
        $this->l2="";
        $this->l1="";
        $this->l0=$code;
        break;
    }
  }
}

$codemgr=new CodeMgr();
$accode="";
$string=$asset;
$string=str_replace("","",$string);
$array=explode("\n",$string);
foreach($array as &$item)
{
  $item=trim($item);
  if(!$item)continue;
  $pieces=explode("\t",$item);
  $level=$pieces[0];
  $name=$pieces[1];
  $code=strtolower(str_replace(array(",","-"," ","/"),"",$name));
  $at="at_asset";

  $codemgr->setparentcode($level,$code);

  showaccount($name,$code,$at,$codemgr->getparentcode($level));
}

$accode="";
$string=$liability;
$string=str_replace("","",$string);
$array=explode("\n",$string);
foreach($array as &$item)
{
  $item=trim($item);
  if(!$item)continue;
  $pieces=explode("\t",$item);
  $level=$pieces[0];
  $name=$pieces[1];
  $code=strtolower(str_replace(array(",","-"," ","/"),"",$name));
  $at="at_liability";

  $codemgr->setparentcode($level,$code);

  showaccount($name,$code,$at,$codemgr->getparentcode($level));
}
$accode="";
$string=$equity;
$string=str_replace("","",$string);
$array=explode("\n",$string);
foreach($array as &$item)
{
  $item=trim($item);
  if(!$item)continue;
  $pieces=explode("\t",$item);
  $level=$pieces[0];
  $name=$pieces[1];
  $code=strtolower(str_replace(array(",","-"," ","/"),"",$name));
  $at="at_equity";

  $codemgr->setparentcode($level,$code);

  showaccount($name,$code,$at,$codemgr->getparentcode($level));
}
$accode="";
$string=$income;
$string=str_replace("","",$string);
$array=explode("\n",$string);
foreach($array as &$item)
{
  $item=trim($item);
  if(!$item)continue;
  $pieces=explode("\t",$item);
  $level=$pieces[0];
  $name=$pieces[1];
  $code=strtolower(str_replace(array(",","-"," ","/"),"",$name));
  $at="at_income";

  $codemgr->setparentcode($level,$code);

  showaccount($name,$code,$at,$codemgr->getparentcode($level));
}
$accode="";
$string=$expense;
$string=str_replace("","",$string);
$array=explode("\n",$string);
foreach($array as &$item)
{
  $item=trim($item);
  if(!$item)continue;
  $pieces=explode("\t",$item);
  $level=$pieces[0];
  $name=$pieces[1];
  $code=strtolower(str_replace(array(",","-"," ","/"),"",$name));
  $at="at_expense";

  $codemgr->setparentcode($level,$code);

  showaccount($name,$code,$at,$codemgr->getparentcode($level));
}

